package com.ruoyi.common.utils;


import com.ruoyi.common.constant.DbGenerateResult;
import com.ruoyi.common.constant.DbGenerateStatus;
import com.ruoyi.project.wenyanwen.generate.domain.DbGenerate;
import org.apache.commons.lang.StringUtils;

public class DbGenerateUtil {

	/**
	 * 获取生成结果描述
	 * 
	 * @param dbGenerate
	 * @return
	 */
	public static String getResult(DbGenerate dbGenerate) {

		switch (dbGenerate.getLastResult()) {
		case DbGenerateResult.SUCCESS:
			return "<font color='green'>生成成功</font>";
		case DbGenerateResult.FAILURE:
			return "<font color='red' title='" + dbGenerate.getErrorLog() + "'>生成失败</font>";
		case DbGenerateResult.STOP:
			return "<font color='red'>用户取消</font>";
		default:
			return "";
		}

	}

	/**
	 * 获取进度条样式
	 * 
	 * @param dbGenerate
	 * @return
	 */
	public static String getProgressStyle(DbGenerate dbGenerate) {

		switch (dbGenerate.getStatus()) {
		case DbGenerateStatus.DOING:
			return "progress-bar-info";
		case DbGenerateStatus.FINISH:
			if (dbGenerate.getProgress() == 100) {
				return "progress-bar-success";
			} else {
				return "progress-bar-danger";
			}
		case DbGenerateStatus.CANCEL:
			return "progress-bar-danger";
		default:
			return "";
		}
	}

	/**
	 * 获取生成状态
	 * 
	 * @param dbGenerate
	 * @return
	 */
	public static String getStatus(DbGenerate dbGenerate) {
		switch (dbGenerate.getStatus()) {
		case DbGenerateStatus.NEW:
			if (StringUtils.equalsIgnoreCase(dbGenerate.getCommand(), "GENERATE")) {
				return "<font color='green'>正在开始... </font>";
			} else {
				return "<font color='red'>正在取消...</font>";
			}
		case DbGenerateStatus.DOING:
			return "<font color='green'>正在生成... </font>";
		case DbGenerateStatus.FINISH:
			return "<font color='green'>已经完成</font>";
		case DbGenerateStatus.CANCEL:
			return "<font color='red'>已经取消</font>";
		default:
			return "";
		}
	}
}
